package basic;

import org.omg.CORBA.portable.OutputStream;

import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;

/**
 * Created by luzl on 4/10/2017.
 */
public class CharacterConvert {
    public static void main(String[] args){
        try {
            byte[] bytes ="中国".getBytes("UTF-8");
            String stringGBK=new String(bytes,"GBK");
            String replaceGBK=new String("新".getBytes("UTF-8"),"GBK");
            //String replaced=stringGBK.replaceAll("[\\x{2E80}-\\x{9FFF}]",replaceGBK);
            String replaced=stringGBK.replaceAll("([x81-xfe][x40-xfe])","a");
            System.out.println(new String(replaced.getBytes("GBK"),"utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        String stringUTF8="，中国";
        Pattern pattern1=Pattern.compile("[\\u4E00-\\u9FA5]");//简体中文
        Pattern pattern2=Pattern.compile("[\\u4E00-\\u9FFF]");//简体中文，繁体中文都包括
        System.out.println(pattern2.matcher(stringUTF8).matches());
        System.out.println(stringUTF8+" cleaned "+stringUTF8.replaceAll("[\\u4E00-\\u9FA5]","新"));


    }
}
